package org.kernely.persistence.service;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.kernely.persistence.Activator;

public class SessionServiceImpl implements SessionService {

	public SessionServiceImpl() {
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see com.prometil.kernely.persistence.service.SessionServiceInterface#getSessionFactory()
	 */
	public SessionFactory getSessionFactory() {
		return Activator.getInstance().getSessionFactory();
	}

	@Override
	public Session getSession() {
		Session currentSession;
		if(!Activator.getInstance().getSessionFactory().getCurrentSession().isOpen())
			currentSession = Activator.getInstance().getSessionFactory().openSession();
		else
			currentSession = Activator.getInstance().getSessionFactory().getCurrentSession();
		if(!currentSession.getTransaction().isActive()) {
			currentSession.beginTransaction();
		}
		return currentSession;
	}

}